package cn.wk.user.controller;

import cn.wk.basic.utils.AjaxResult;
import cn.wk.user.domain.User;
import cn.wk.user.domain.dto.LoginInfoDto;
import cn.wk.user.service.ILoginInfoService;
import cn.wk.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    /**
     * 检查手机号是否有重复
     * @param user
     * @return
     */
    @PostMapping("/checkPhone")
    public AjaxResult checkPhone(@RequestBody User user){
        System.out.println(user);
        try{
            //根据手机号去数据库匹配是否有重复的
            userService.checkPhone(user.getPhone());
            return new AjaxResult();
        }catch(Exception e){
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 注册用户
     */
    @Autowired
    private ILoginInfoService iLoginInfoService;
    @PostMapping("/register")
    public AjaxResult register (@RequestBody LoginInfoDto loginInfoDto){
        System.out.println(loginInfoDto);
        try{
            iLoginInfoService.register(loginInfoDto);
            return new AjaxResult();
        }catch(Exception e){
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }
}
